﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Room : MonoBehaviour
{
    /// <summary>
    /// 单元格宽高
    /// </summary>
    float cellWidth = 1;
    float cellHeigth = 1;

    /// <summary>
    /// 房间中心
    /// </summary>
    public Vector3 roomCenter;

    /// <summary>
    /// 是否为边缘
    /// </summary>
    public bool isEdge = false;

    /// <summary>
    /// 生成墙壁和地板的房间
    /// </summary>
    /// <param name="headPos">左定点</param>
    /// <param name="roomWidth">房间宽度</param>
    /// <param name="roomHeigth">房间高度</param>
    /// <param name="wallPrefab">墙壁预设</param>
    /// <param name="floorPrefab">地板预设</param>
    public Room(Vector2 headPos, int roomWidth, int roomHeigth, GameObject wallPrefab, GameObject floorPrefab)
    {
        float posLeft = headPos.x;
        float posTop = headPos.y;

        float startLeft = posLeft;
        print(posLeft + "   " + posTop);
        for (int i = 0; i < roomHeigth; i++)
        {
            for (int j = 0; j < roomWidth; j++)
            {
                //铺地板
                Instantiate(floorPrefab, new Vector3(posLeft, posTop, 0), Quaternion.identity);
                //铺墙
                if (i == 0 || i == roomHeigth - 1 || j == 0 || j == roomWidth - 1)
                {
                    GameObject wall = Instantiate(wallPrefab, new Vector3(posLeft, posTop, 0), Quaternion.identity);
                }
                else
                {
                    //内部区域

                }

                //控制数据
                posLeft += cellWidth;

                if (j == roomWidth - 1)
                {
                    posLeft = startLeft;
                    posTop -= cellHeigth;
                }

                if ( i == roomHeigth / 2 && j == roomWidth / 2)
                {
                    //则为房间中心
                    roomCenter.x = posLeft;
                    roomCenter.y = posTop;
                }
            }
        }
    }
}
